********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************
global y "lncdisbur_w199"
global ec3 "dT1e13 dT2e13 dT3e13 dT4e13 dT5e13 dT7e13 dT8e13 dT9e13 dT10e13 dT11e13 dT12e13"
global ed3top "dT1dtop85e13 dT2dtop85e13 dT3dtop85e13 dT4dtop85e13 dT5dtop85e13 dT7dtop85e13 dT8dtop85e13 dT9dtop85e13 dT10dtop85e13 dT11dtop85e13 dT12dtop85e13"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2013m6) tm(2014m6) 1
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gruPLACEBO, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preannPLACEBO, keepus(e13 dtop85e13 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinmPLACEBO, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2013m7)&time<=tm(2014m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

gen byte dT1=(time==tm(2013m7))
gen byte dT2=(time==tm(2013m8))
gen byte dT3=(time==tm(2013m9))
gen byte dT4=(time==tm(2013m10))
gen byte dT5=(time==tm(2013m11))
gen byte dT7=(time==tm(2014m1))
gen byte dT8=(time==tm(2014m2))
gen byte dT9=(time==tm(2014m3))
gen byte dT10=(time==tm(2014m4))
gen byte dT11=(time==tm(2014m5))
gen byte dT12=(time==tm(2014m6))
run RO_tdintera 12 "e13 dtop85e13 exlnassets excashas"

**# Bookmark (output - columns 1 and 2)
est clear
cd $outputdirectory
reghdfe $y $ec3 $controls $regcommands
est save TABIII_C12
reghdfe $y $ed3top $controls $regcommands
est save TABIII_C12, append
cd ..
